﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace string常用方法
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "sdhshaduwHHA";
            string s1 = s.ToLower();  //字符串是不可改变的，所以s并没有发生改变
            string s2 = s.ToUpper();

            Console.WriteLine(s);
            Console.WriteLine(s1);
            Console.WriteLine(s2);

            Console.WriteLine("请输入用户名：");
            string userName = Console.ReadLine();

            if (userName.ToLower().Trim() == "admin")  //并没有改变原来的字符串，只是返回了一个新的字符串
            {
                Console.WriteLine("用户名存在！");
            }
            else
            {
                Console.WriteLine("用户名不存在！");
            }

            string str = "    addsf  ";
            Console.WriteLine(str.Length);
            str.Trim();                  //还是那就话，string不可改变
            Console.WriteLine(str.Length);
            str = str.Trim();
            Console.WriteLine(str.Length);

            string str1 = "admin";
            string str2 = "Admin";
            Console.WriteLine(str1 == str2);
            Console.WriteLine(str1.ToLower() == str2.ToLower());
            Console.WriteLine(str1.Equals(str2, StringComparison.OrdinalIgnoreCase));

            string[] str = new string[3] { "tom", "linda", "aimy" };
            string str2 = string.Join("|", str);
            Console.WriteLine(str2);

            string line = Console.ReadLine();
            string[] lines = line.Split(',', '|');
            foreach (string l in lines)
            {
                Console.WriteLine(l);
            }

            string[] lines = System.IO.File.ReadAllLines(@"E:\1.txt",Encoding.Default);
            for (int i = 0; i < lines.Length; i++)
            {
                Console.WriteLine("第{0}行：{1}", i + 1, lines[i]);
            }

            Console.ReadKey();
        }
    }
}
